import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import UnoCSS from '@unocss/svelte-scoped/preprocess';

const prod = import.meta.env !== 'development';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://kit.svelte.dev/docs/integrations#preprocessors
	// for more information about preprocessors
	preprocess: [
		vitePreprocess(),
		UnoCSS({
			// 不要在开发中组合类名，因为它们会变得难以调试
			combine: prod
			// ... preprocessor options
		})
	],

	kit: {
		// ssr: false, // 禁用服务器端渲染
		// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
		// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
		// See https://kit.svelte.dev/docs/adapters for more information about adapters.
		adapter: adapter({
			pages: 'build', // 将预渲染页面写入的目录。它默认为`build`.
			assets: 'build', // 资源 打包输出目录包括Svelte-kit输出的js和css
			fallback: null // 指定 SPA 模式的后备页面，例如`index.html`或`200.html`或`404.html`。
		}),
		alias: {
			$components: 'src/components',
			$utils: 'src/utils',
			'@': 'src'
		}
		// hydrate the <div id="svelte"> element in src/app.html
		// target: '#svelte',
		// vite: {
		// 	ssr: {
		// 		noExternal: ['@unocss/svelte-scoped']
		// 	},
		// }
	},

	onwarn(warning, rollupWarn) {
		// console.log('\x1b[35m' + 'Tip：' + warning.code + '; ' + warning.message + '\x1b[0m');
		// 忽略特定的警告
		if (warning.code && warning.code.startsWith('a11y-')) return;
		// 对于其他警告，正常输出
		rollupWarn(warning);
	}
};

export default config;
